package com.beagle.njddapp.ui.activity;

import android.content.Intent;
import android.graphics.Color;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import androidx.annotation.Nullable;

import com.beagle.njddapp.R;
import com.beagle.njddapp.base.BaseMvpActivity;
import com.beagle.njddapp.bean.CompanyBean;
import com.beagle.njddapp.bean.owner.NjBean;
import com.beagle.njddapp.bean.UploadBean;
import com.beagle.njddapp.bean.UserInfoBean;
import com.beagle.njddapp.core.UserService;
import com.beagle.njddapp.ui.presenter.UserInfoPresenter;
import com.beagle.njddapp.ui.view.UserInfoView;
import com.beagle.njddapp.utils.StatusBarUtil;
import com.bumptech.glide.Glide;
import com.bumptech.glide.request.RequestOptions;

import java.util.List;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * @author hxx
 * @date 2021-03-04 20:21
 * 用户信息
 */
public class UserInfoActivity extends BaseMvpActivity<UserInfoView, UserInfoPresenter> implements UserInfoView {

    @BindView(R.id.commom_title_tv)
    TextView tvTitle;
    @BindView(R.id.common_container)
    RelativeLayout container;
    @BindView(R.id.common_tv_right)
    TextView tvRight;
    @BindView(R.id.tv_name)
    TextView tvName;
    @BindView(R.id.tv_sex)
    TextView tvSex;
    @BindView(R.id.tv_identity)
    TextView tvCard;
    @BindView(R.id.tv_phone)
    TextView tvPhone;
    @BindView(R.id.tv_address)
    TextView tvAddress;
    @BindView(R.id.tv_concat)
    TextView tvConcat;
    @BindView(R.id.tv_concat_phone)
    TextView tvConcatPhone;
    @BindView(R.id.tv_company)
    TextView tvCompany;
    @BindView(R.id.tv_drive)
    TextView tvDirver;
    @BindView(R.id.iv1)
    ImageView iv1;
    @BindView(R.id.iv2)
    ImageView iv2;
    @BindView(R.id.tv_car)
    TextView tvCar;
    @BindView(R.id.tv_invate)
    TextView tvInavate;
    @BindView(R.id.tv_invate_name)
    TextView tvInavateName;
    @Override
    public int getLayoutId() {
        return R.layout.activity_userinfo;
    }

    @Override
    public void init() {
        StatusBarUtil.immersive(this,Color.WHITE);
        StatusBarUtil.darkMode(this);
        tvTitle.setText("个人信息");
        tvRight.setText("修改");
        setData();
    }
    private void setData() {
        UserInfoBean userInfoBean= UserService.getInstance().getUserInfoBean();

        tvName.setText(userInfoBean.getUserName());
        if (userInfoBean.getGender()==1){
            tvSex.setText("男");
        }else {
            tvSex.setText("女");
        }
        tvPhone.setText(userInfoBean.getPhone());
        tvCard.setText(userInfoBean.getIdcard());
        tvConcat.setText(userInfoBean.getEmergencyContact());
        tvConcatPhone.setText(userInfoBean.getEmergencyContactPhone());
        tvCompany.setText(userInfoBean.getCompany());
        tvAddress.setText(userInfoBean.getAddress());
        tvDirver.setText(userInfoBean.getDrivingAge()+"");
        tvCar.setText(userInfoBean.getOftenMechNum());
        tvInavate.setText(userInfoBean.getInvitationCode());
        tvInavateName.setText(userInfoBean.getInvitationName());
        Glide.with(this).load(userInfoBean.getLicenceUrlA()).apply(new RequestOptions().placeholder(R.mipmap.register_btn_drivea)).into(iv1);
        Glide.with(this).load(userInfoBean.getLicenceUrlB()).apply(new RequestOptions().placeholder(R.mipmap.register_btn_driveb)).into(iv2);

    }

    @Override
    public UserInfoView getMvpView() {
        return this;
    }

    @Override
    public UserInfoPresenter createPresenter() {
        return new UserInfoPresenter();
    }

    @Override
    public void onError(String message) {

    }
    @OnClick({R.id.common_back_iv,R.id.common_tv_right})
    public void onCLick(View view){
        switch (view.getId()){
            case R.id.common_back_iv:
                onBackPressed();
                break;
            case R.id.common_tv_right:
                startActivityForResult(new Intent(this,UserInfoUpdateActivity.class),504);
                break;
        }
    }

    @Override
    public void success() {

    }

    @Override
    public void uploadSuccess(UploadBean data) {

    }

    @Override
    public void showCampany(List<CompanyBean> data) {

    }

    @Override
    public void showRunNj(List<NjBean> results) {

    }

    @Override
    protected void onRestart() {
        super.onRestart();
        setData();
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
        super.onActivityResult(requestCode, resultCode, data);

    }
}
